import 'package:get/get.dart';
import 'package:hygf/http/file_transfer/down_cap.dart';

import '../../../../bean/CustomerList.dart';
import '../../../../http/DioClient.dart';
import '../../../../view/image_picker_widget.dart';
import '../CustomerDetailPage.dart';
import 'state.dart';

class DesignMsgLogic extends GetxController {
  final DesignMsgState state = DesignMsgState();

   @override
  void onReady() {
    super.onReady();
  }

  Future<void> initImgUrl() async {
    if((state.designDrawLink.designDrawPhoto??"").isNotEmpty){
      state.designDrawPhotoController.resetImages([]);
      List<ImagePickerData> designDrawPhoto = await DioClient().requestImgUrl(state.designDrawLink.designDrawPhoto);
      state.designDrawPhotoController.addImages(designDrawPhoto);
    }
    if((state.designDrawLink.billMaterials??"").isNotEmpty){
      state.billMaterialsController.resetImages([]);
      List<ImagePickerData> billData = await DioClient().requestImgUrl(state.designDrawLink.billMaterials);
      state.billMaterialsController.addImages(billData);
    }
    if((state.designDrawLink.other??"").isNotEmpty){
      state.otherController.resetImages([]);
      List<ImagePickerData> otherData = await DioClient().requestImgUrl(state.designDrawLink.other);
      state.otherController.addImages(otherData);
    }
    if((state.designDrawLink.cadFile??"").isNotEmpty){
      state.cadFileController.resetImages([]);
      List<ImagePickerData> cadFileData = await DioClient().requestImgUrl(state.designDrawLink.cadFile);
      state.cadFileController.addImages(cadFileData);
    }
    update();
  }

  Future<void> setData(DesignDrawLink? tempData) async {
    if (tempData != null) {
      state.designDrawLink = tempData;
      await initImgUrl();
      Get.find<RefreshTabLogic>(tag: "2").refreshTabBar();
    }
  }
}
